package com.fourpigeon.dao;

import java.util.List;

import com.fourpigeon.domain.BlogDaily;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fourpigeon.domain.User;
import org.springframework.stereotype.Repository;

/**
 * User相关数据库操作
 */
@Mapper
@Repository
public interface UserDao {
    @Select("select * from tb_user where id = #{id}")
    public User getById(Long id);
    @Select("select * from tb_user")
    public List<User> getAll();
    @Update("update tb_user set password=#{password},name=#{name},icon=#{icon},phone=#{phone},sex=#{sex} where id = #{id}")
    public boolean update(User user);
    @Insert("insert into tb_user values(#{id},#{openId},#{name},#{sex},#{password},#{icon},#{phone},#{introduce},#{fans},#{followee},#{birthday},#{createTime},#{updateTime})")
    public boolean save(User user);
    @Delete("delete from tb_user where id = #{id}")
    public boolean delete(Long id);
    @Select("select * from tb_user where name = #{userName}")
    User getByUserName(String userName);
    @Select("select * from tb_user where phone = #{phone}")
    User getByPhone(String phone);

    @Update("update tb_user set name=#{name},icon=#{icon},phone=#{phone},sex=#{sex},introduce=#{introduce},birthday=#{birthday} where id = #{id}")
    public boolean updateUserInfo(User user);

    @Update("update tb_user set password=#{password} where id=#{id}")
    public boolean updatePassword(User user);

    @Update("update tb_user set userName=#{userName} where id=#{id}")
    public boolean updateName(Long id,String userName);

    @Update("update tb_user set icon=#{icon} where id=#{id}")
    public boolean updateIcon(Long id,String icon);

    @Select("select * from tb_user where id<#{startId} order by createTime DESC  limit 6")
    public List<BlogDaily> getByUserId(Long startId);

    @Update("update tb_user set fans = fans+1 where id = #{userId}")
    public boolean addFans(Long userId);

    @Update("update tb_user set fans = fans-1 where id = #{userId}")
    public boolean subFans(Long userId);

    @Update("update tb_user set followee = followee+1 where id = #{userId}")
    public boolean addFollowee(Long userId);

    @Update("update tb_user set followee = followee-1 where id = #{userId}")
    public boolean subFollowee(Long userId);
}
